package com.cheyunkeji.er.fragment.evaluate;

import android.content.Intent;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.MyFragmentManager;
import com.cheyunkeji.er.activity.evaluate.AddCarArchiveActivity;
import com.cheyunkeji.er.activity.evaluate.AddClientActivity;
import com.cheyunkeji.er.adapter.MyFragmentPagerAdapter;
import com.cheyunkeji.er.base.BaseFragment;
import com.cheyunkeji.er.utils.TabLayoutAdjustBoundUtils;
import com.cheyunkeji.er.view.TopBar;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by Michael on 2017/3/17 15:46.
 */

public class ArchiveFragment extends BaseFragment {

    @BindView(R.id.v_topbar)
    TopBar vTopbar;
    @BindView(R.id.tl_archive)
    TabLayout tlArchive;
    @BindView(R.id.vp_evaluate_archive)
    ViewPager vpEvaluateArchive;

    private ArrayList<String> titleList;
    private ArrayList<Fragment> fragList;
    private MyFragmentPagerAdapter fragAdapter;


    @Override
    protected void doInflaterView(LayoutInflater inflater, ViewGroup container) {
        contentView = inflater.inflate(R.layout.er_frag_evaluate_archive, container, false);
        ButterKnife.bind(this, contentView);
    }

    @Override
    protected void init() {
        titleList = new ArrayList<>();
        fragList = new ArrayList<>();
        titleList.add("车辆档案");
        titleList.add("车主档案");
        fragList.add(MyFragmentManager.getInstance().getFrag(CarArchiveFragment.class));
        fragList.add(MyFragmentManager.getInstance().getFrag(CarOwnerArchiveFragment.class));
    }

    @Override
    protected void initView() {
        vTopbar.setTitle(getString(R.string.archive));
        vTopbar.setRight(getString(R.string.add_new), 0,80, this);
        fragAdapter = new MyFragmentPagerAdapter(getActivity().getSupportFragmentManager(), titleList, fragList);
        vpEvaluateArchive.setAdapter(fragAdapter);
        tlArchive.setupWithViewPager(vpEvaluateArchive);
        tlArchive.setTabsFromPagerAdapter(fragAdapter);
        TabLayoutAdjustBoundUtils.setIndicator(getActivity(), tlArchive, 50, 50);
    }

    @Override
    protected void initData() {
        vpEvaluateArchive.getCurrentItem();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.vRight:
                if(tlArchive.getSelectedTabPosition() == 0)
                    startActivity(new Intent(getActivity(), AddCarArchiveActivity.class));
                else{
                    Intent intent = new Intent(getActivity(), AddClientActivity.class) ;
                    intent.putExtra("name",((CarOwnerArchiveFragment)fragList.get(1)).getSearchText());
                    startActivity(intent);
                }
                break;
            default:
                break;
        }
    }
}
